using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;

namespace G2007.CodeGen.Settings
{
    [Serializable]
    public class Config
    {

        private string file;


        public string File { get { return file; } set { file = value; } }

        public Config ()
        {

        }



        // TODO: Add the other check boxes to the remember state
        // for this application

        public static void SaveConfig ( main _main )
        {
            if ( _main.Config == null )
            {
                _main.Config = new Config ();
            }

            _main.Config.file = _main.txtScript.Text;

            if ( System.IO.File.Exists ( _main.AppPath + "\\" +
                        System.Configuration.ConfigurationSettings.AppSettings[ "CONFIG_FILE" ] ) )
            {
                System.IO.File.Delete ( _main.AppPath + "\\" +
                        System.Configuration.ConfigurationSettings.AppSettings[ "CONFIG_FILE" ] );
            }

            Kellogs.SerialUtils.GetObject (
                typeof ( Config ) , _main.Config ).Save (
                    _main.AppPath + "\\" +
                        System.Configuration.ConfigurationSettings.AppSettings[ "CONFIG_FILE" ] );
        }

        public static void LoadConfig ( main _main )
        {
            if ( System.IO.File.Exists (
                _main.AppPath + "\\" +
                        System.Configuration.ConfigurationSettings.AppSettings[ "CONFIG_FILE" ] ) )
            {
                XmlDocument xmlDoc = new XmlDocument ();
                xmlDoc.Load ( _main.AppPath + "\\" +
                        System.Configuration.ConfigurationSettings.AppSettings[ "CONFIG_FILE" ] );

                Exception ex;
                _main.Config = ( Config ) Kellogs.SerialUtils.GetObject ( xmlDoc , typeof ( Config ) , out ex );

                if ( ex == null )
                {
                    _main.txtScript.Text = _main.Config.File;
                }
            }

        }

    }
}
